import { AnyAction } from "redux";
import { GlobalState } from "@renderer/redux/types";
import produce from "immer";
import * as types from "@renderer/redux/mutation-types";

const globalState: GlobalState = {
	isCollapse: false,
	token: ""
};

const global = (state: GlobalState = globalState, action: AnyAction) => {
	return produce(state, draftState => {
		switch (action.type) {
			case types.SET_TOKEN:
				draftState.token = action.token;
				break;
			case types.UPDATE_COLLAPSE:
				draftState.isCollapse = action.isCollapse;
				break;
			// 不需要 default 返回，immer 会处理
		}
	});
};

export default global;
